home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / remalloc.c < prev    next >
C/C++ Source or Header  |  1986-04-20  |  3KB  |  68 lines

  1.  
  2.  
  3. /** RemAlloc.c **************************************************************/
  4. /*  ChipAlloc(), ExtAlloc(), RemAlloc(), RemFree().                  */
  5. /*  ALLOCators which REMember the size allocated, for simpler freeing.         */
  6. /*                                                                          */
  7. /* Date      Who Changes                                                    */
  8. /* --------- --- -----------------------------------------------------------*/
  9. /* 16-Jan-86 sss Created from DPaint/DAlloc.c                               */
  10. /* 23-Jan-86 jhm Include Compiler.h, check for size > 0 in RemAlloc.      */
  11. /* 25-Jan-86 sss Added ChipNoClearAlloc,ExtNoClearAlloc                     */
  12. /*                                                                   */
  13. /* By Jerry Morrison and Steve Shaw, Electronic Arts.                       */
  14. /* This software is in the public domain.                                 */
  15. /*                                                                   */
  16. /* This version for the Commodore-Amiga computer.                    */
  17. /*                                                                        */
  18. /****************************************************************************/
  19. #ifndef COMPILER_H
  20. #include "iff/compiler.h"
  21. #endif
  22.  
  23. #include "exec/nodes.h"
  24. #include "exec/memory.h"
  25. #include "iff/remalloc.h"
  26.  
  27. /** RemAlloc ****************************************************************/
  28. UBYTE *RemAlloc(size,flags) LONG size, flags; {
  29.     register LONG *p = NULL;  /* (LONG *) for the sake of p++, below */
  30.     register LONG asize = size+4;
  31.     if (size > 0)
  32.      p = (LONG *)AllocMem(asize,flags);
  33.     if (p != NULL)
  34.      *p++ = asize;  /* post-bump p to point at clients area*/
  35.     return((UBYTE *)p);
  36.     }
  37.  
  38. /** ChipAlloc ***************************************************************/
  39. UBYTE *ChipAlloc(size) LONG size; {
  40.     return(RemAlloc(size, MEMF_CLEAR|MEMF_PUBLIC|MEMF_CHIP));
  41.     }
  42.     
  43. /** ChipNoClearAlloc ********************************************************/
  44. UBYTE *ChipNoClearAlloc(size) LONG size; {
  45.     return(RemAlloc(size, MEMF_PUBLIC|MEMF_CHIP));
  46.     }
  47.     
  48. /** ExtAlloc ****************************************************************/
  49. UBYTE *ExtAlloc(size) LONG size; {
  50.     return(RemAlloc(size, MEMF_CLEAR|MEMF_PUBLIC));
  51.     }
  52.  
  53. /** ExtNoClearAlloc *********************************************************/
  54. UBYTE *ExtNoClearAlloc(size) LONG size; {
  55.     return(RemAlloc(size, MEMF_PUBLIC));
  56.     }
  57.  
  58. /** RemFree *****************************************************************/
  59. UBYTE *RemFree(p) UBYTE *p; {
  60.     if (p != NULL) {
  61.      p -= 4;
  62.      FreeMem(p, *((LONG *)p));
  63.      }
  64.     return(NULL);
  65.     }
  66.  
  67.  
  68. ready: